package com.xinzhitong.www.mapper;

import com.xinzhitong.www.pojo.ExamLocation;
import com.xinzhitong.www.pojo.ExamTime;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 考证控制器
 *
 * @author 钟伟良
 */
@Repository
public interface CredentialMapper {

    /**
     * 证书id获取证书介绍
     *
     * @param id 证书id
     * @return 证书介绍
     */
    @Select("SELECT introduction FROM credential where id=#{id}")
    String selectIntroduction(Integer id);

    /**
     * 证书id获取证书要求
     *
     * @param credentialId 证书id
     * @return 证书要求
     */
    @Select("SELECT text FROM credential_request where credential_id=#{credentialId}")
    List<String> selectRequest(Integer credentialId);

    /**
     * 考证id获取考证地点
     *
     * @param credentialId 考证id
     * @return 考证地点
     */
    @Select("SELECT id,province,city,area,address FROM exam_location where credential_id=#{credentialId}")
    List<ExamLocation> selectExamLocation(Integer credentialId);

    /**
     * 考证id获取考试场次
     *
     * @param locationId 考证地点id
     * @return 考试场次
     */
    @Select("SELECT startTime,endTime,id FROM credential_exam_information where locationId=#{locationId}")
    List<ExamTime> selectTime(Integer locationId);

    /**
     * 证书id获取报名要求
     *
     * @param credentialId 证书id
     * @return 报名要求
     */
    @Select("SELECT text FROM credential_request where credential_id=#{credentialId} and be_checked=1")
    List<String> selectCheckRequired(Integer credentialId);

    /**
     * 证书id获取证书图片
     *
     * @param id 证书id
     * @return 证书图片
     */
    @Select("SELECT picture FROM credential where id=#{id}")
    String selectPicture(Integer id);

    /**
     * 工种id获取证书概览
     *
     * @param professionId 工种id
     * @return 证书概览
     */
    @Select("SELECT picture,credentialId,name,number FROM credential_general_all where professionId=#{professionId}")
    List<Map<String, Object>> selectGeneral(Integer professionId);

    //    @Insert("
//    user_watched_class(username,class_id)VALUES(#{username},#{classId})")

    /**
     * 立即报名考证
     *
     * @param username 用户名
     * @param timeId   考证时间
     * @return 插入是否成功
     */
    @Insert("INSERT INTO user_has_exam_time(username,exam_time_id)VALUES(#{username},#{timeId})")
    Integer insertExam(String username, Integer timeId);

    @Select("SELECT exam_time_id FROM user_has_exam_time where username=#{username}  AND exam_time_id=#{timeId}")
    Integer selectTimeId(String username, Integer timeId);

    @Select("SELECT id FROM exam_time where id=#{timeId}")
    Integer selectTimeIdExam(Integer timeId);
}
